package com.wiscamp.ninechapters.problems.infrastructure.mappers.tasks;

import com.wiscamp.ninechapters.problems.infrastructure.po.tasks.AssignmentPO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.Collection;

/**
 * 习题集分发记录仓储对象
 *
 * @author yifeng
 */
@Repository
public interface AssignmentMapper extends JpaRepository<AssignmentPO, Long>, JpaSpecificationExecutor<AssignmentPO> {
    /**
     * 通过习题集编号获取分发记录列表
     *
     * @param setId
     * @return
     */
    @Query(value = "select e from AssignmentPO e where e.setId = :setId")
    Collection<AssignmentPO> findListBySet(long setId);

    @Query(value = "select count(e.assignmentId) from AssignmentPO e where e.assignmentTime between :startDate and :endDate")
    int findAssignmentQuantityByDate(LocalDate startDate, LocalDate endDate);

    /**
     * 分页查询
     *
     * @param spec
     * @param pageable
     * @return
     */
    Page<AssignmentPO> findAll(Specification<AssignmentPO> spec, Pageable pageable);
}